﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LogManager.Base;
using LogManager.Base.Models.Projections;
using Raven.Client.Indexes;

namespace LogManager.LocalStorage.Indexes
{
    public class Events_PerDate : AbstractIndexCreationTask<Event, EventsPerDataProjection>
    {
        public Events_PerDate()
        {
            Map = events =>
                  from e in events
                  select new {LogName = e.LogName, Date = e.TimeStamp.Date, Count = 1};
            Reduce = results =>
                     from r in results
                     group r by new {LogName = r.LogName, Date = r.Date} into g
                     select new { LogName = g.Key.LogName, Date = g.Key.Date, Count = g.Sum(x => x.Count) };
        }
    }
}
